package com.jg.test.Page;

import com.jg.test.AnyTest;
import com.jg.test.Dice;

import java.lang.reflect.Field;
import java.util.ArrayList;

// 激活骰子
public class Battle002 extends Page {
    private boolean n = true;

    public static ArrayList<Dice> dice = new ArrayList<>();

    @Override
    public void effect() throws IllegalAccessException, NoSuchMethodException {
        // 备份
        dice.clear();
        for (int i = 0; i < 6; i++) {
            Dice dice = new Dice();
            Battle002.dice.add(dice);
        }
        for (int i = 0; i < 6; i++) {
            dice.get(i).setUsed(Dice.dice.get(i).isUsed());
            dice.get(i).setPoint(Dice.dice.get(i).getPoint());
        }
        // 导入反射
        Class<?> clazz = AnyTest.team.get(4).getClass();
        Field[] declaredFields = clazz.getDeclaredFields();
        // 发送消息
        Dice.diceShow();
        System.out.println();
        System.out.println("请按照技能描述需求按顺序激活骰子");
        // 记录选择，屏蔽重复选择
        int choices = 0;
        while (declaredFields[Battle001.choice + 9].getInt(AnyTest.team.get(4)) != choices) {
            int choice = Page.numGet(6);
            if (dice.get(choice).isUsed()) {
                System.out.println("不可选择重复骰子");
                n = false;
                break;
            }
            dice.get(choice).setUsed(true);
            choices++;
            System.out.println("已记录，请继续选择");
        }
    }

    @Override
    public void sendMessage() {
        System.out.println("等待检验");
    }

    @Override
    public void next() {
        if (n) {
            // 下一流程
            AnyTest.pageNavigation.add(new Battle003());
        } else {
            // 重走本流程
            System.out.println("不可以重复选择骰子");
            AnyTest.pageNavigation.add(new Battle002());
        }
    }

}
